;( function () {
	"use strict";
    var param_map = Result.getLocationParamObject();
    var global_param_map;
	
	$( function () {
		if(!ifUser()){
			return;
		}
		queryOrderCount();
		queryUserInfo();
		
		$("#tuijian").click(function(){
			//todo 推荐按钮
		});
		
	}); 

	/**
	 * 获取订单的数量
	 */
	function queryOrderCount(){
		var params = {
			"userId" : 	USER.userId,
		};
		$.ajax(getAjaxOps('/order/qryOrderCount', params)
		).done(function(res){
            if(res.resultCode == 0) {
               $("#order_number_dai_fu_kuan").html(res.data.waitingForPay);
               $("#order_number_dai_fa_huo").html(res.data.waitingForSend);
               $("#order_number_dai_shou_huo").html(res.data.waitingForCheck);
               $("#order_number_all").html(res.data.allCnt);
            }
	    });
	}
	/**
	 * 获取用户信息
	 */
	function queryUserInfo(){
		var params = {
			"userId" : 	USER.userId,
		};
		$.ajax(getAjaxOps('/user/getUserInfo', params)
		).done(function(res){
			var data = res.data;
            if(res.resultCode == 0) {
            	$("#user_photo").attr("src", IMG_PRE + data.url);
            	$("#user_phone").html(data.phone);
            } else {
            	$("body").tips(res.data);
            }
	    });
	}
	 
	/**
	 * 跳到首页
	 */
	window.toIndex = function(){
		Result.forward("index.html", {});
	};
	
	/**
	 * 跳到用户信息
	 */
	window.toUserInfo = function(){
		Result.forward("userInfos.html", {});
	};
	
	/**
	 * 跳到我的收藏
	 */
	window.toCollection = function(){
		Result.forward("myCollection.html", {});
	};
	
	/**
	 * 帮助
	 */
	window.toBangzhu = function(){
		Result.forward("help.html", {});
	};
	
	/**
	 * 反馈
	 */
	window.toBack = function(){
		Result.forward("back.html", {});
	};
	window.kefu = function(){
		$.ajax(
			getAjaxOps('/config/getQQ', {})
		).done(function (res) {
			if(res.resultCode == 0){
				window.frontshoes.chat(res.data.toString());
			}
		});
	};
	/**
	 * 购物车
	 */
	window.toCard = function(){
		Result.forward("cart.html", {});
	};
	
	/**
	 * 我的订单
	 */
	window.toMyOrder = function(type){
		//0 全部订单
		//1 代付款
		//2代发货
		//3待收货
		if(type === undefined || type == null || type == ""){
			Result.forward("orderList.html",{});
		}else{	
			Result.forward("orderList.html", {"type" : type});
		}
	};

}( window ) );
